//
//  DoctorInfoHeaderView.m
//  QuickCure
//
//  Created by 凉气的Mac on 16/9/12.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "DoctorInfoHeaderView.h"

#import "FocusDoctorViewButton.h"

#import "FocusDoctorModel.h"

#import <UIImageView+WebCache.h>

@interface DoctorInfoHeaderView ()

@property(nonatomic,strong)  NSMutableArray *btnArray;

/**
 *  医生头像
 */
@property(nonatomic,weak) UIImageView *doctorIcon;

/**
 *  医生姓名
 */
@property(nonatomic,weak) UILabel *nameLabel;

/**
 *  医生职位
 */
@property(nonatomic,weak) UILabel *positionLabel;

/**
 *  所属医院
 */
@property(nonatomic,weak) UILabel *hospitalLabel;

/**
 *  手术按钮
 */
@property(nonatomic,weak) FocusDoctorViewButton *operationBtn;

/**
 *  鲜花按钮
 */
@property(nonatomic,weak) FocusDoctorViewButton *flow;

/**
 *  锦旗按钮
 */
@property(nonatomic,weak) FocusDoctorViewButton *banner;


@end

@implementation DoctorInfoHeaderView


-(NSMutableArray *)btnArray{
    
    if (_btnArray == nil) {
        
        _btnArray = [NSMutableArray array];
        
    }
    
    return _btnArray;
}


-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        //设置界面
        [self setupUI];
        
    }
    return self;
}

#pragma mark --
#pragma mark --设置界面
-(void)setupUI{
    

    
    //医生头像
    UIImageView *doctorIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"illness_img_person.png"]];
    
    self.doctorIcon = doctorIcon;
    
    doctorIcon.layer.cornerRadius = 40;
    
    doctorIcon.clipsToBounds = YES;
    
    [self addSubview:doctorIcon];
    
    [doctorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.equalTo(self).offset(15);
        
        make.width.height.equalTo(@80);
    }];
    
    //医生名字
    UILabel *nameLabel = [[UILabel alloc]init];
    
    self.nameLabel = nameLabel;
    
    [self addSubview:nameLabel];
    
    nameLabel.text = @"王医生";
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(20);
        
        make.left.equalTo(doctorIcon.mas_right).offset(10);
        
    }];
    
    //医生职位
    UILabel *positionLabel = [[UILabel alloc]init];
    
    self.positionLabel = positionLabel;
    
    [self addSubview:positionLabel];
    
    positionLabel.text = @"副主任医师";
    
    positionLabel.font = [UIFont systemFontOfSize:15];
    
    positionLabel.textColor = [UIColor colorWithWhite:0.702 alpha:1.000];
    
    [positionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(nameLabel);
        
        make.left.equalTo(nameLabel.mas_right).offset(10);
        
    }];
    
    //所属医院
    UILabel *hospitalLabel = [[UILabel alloc]init];
    
    self.hospitalLabel = hospitalLabel;
    
    [self addSubview:hospitalLabel];
    
    hospitalLabel.text = @"上海长征医院";
    
    hospitalLabel.textColor = [UIColor colorWithWhite:0.702 alpha:1.000];
    
    [hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(nameLabel.mas_bottom).offset(20);
        
        make.left.equalTo(nameLabel);
        
        make.right.equalTo(self).offset(-90);
        
    }];
    
    
    //手术按钮
    FocusDoctorViewButton *operationBtn = [self addBtnWithImage:[UIImage imageNamed:@"yuyueliang"]];
    
    self.operationBtn = operationBtn;
    
   // 鲜花按钮
    FocusDoctorViewButton *flow = [self addBtnWithImage:[UIImage imageNamed:@"xianhua"]];
    
    self.flow = flow;
    
    [flow mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.doctorIcon.mas_bottom).offset(15);
        
        make.height.equalTo(@30);
        
        make.width.equalTo(@100);
        
        make.left.equalTo(operationBtn.mas_right).offset(20);
        
    }];

    //锦旗按钮
    FocusDoctorViewButton *banner = [self addBtnWithImage:[UIImage imageNamed:@"jinqi"]];
    
    self.banner = banner;
    
    [banner mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.doctorIcon.mas_bottom).offset(15);
        
        make.height.equalTo(@30);
        
        make.width.equalTo(@100);
        
        make.left.equalTo(flow.mas_right).offset(20);
        
    }];
    
}


-(FocusDoctorViewButton *)addBtnWithImage:(UIImage *)image{
    
    FocusDoctorViewButton *button = [[FocusDoctorViewButton alloc]init];
    
    [self.btnArray addObject:button];
    
    [button setTitle:@"34" forState:UIControlStateNormal];
    
    [self addSubview:button];
    
    [button setImage:image forState:UIControlStateNormal];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.doctorIcon.mas_bottom).offset(15);
        
        make.height.equalTo(@30);
        
        make.width.equalTo(@100);
        
        make.left.equalTo(self.doctorIcon).offset(20);
        
    }];
    
    return button;
    
    
}


-(void)setModel:(FocusDoctorModel *)model{

    self.nameLabel.text = model.doctor_name;
    
    self.hospitalLabel.text = model.doctor_hospital_name;
    
    self.positionLabel.text = model.doctor_title_name;
    
    [self.doctorIcon sd_setImageWithURL:[NSURL URLWithString:model.doctor_portrait] placeholderImage:[UIImage imageNamed:@"illness_img_person.png"]];
    
    [self.operationBtn setTitle:[NSString stringWithFormat:@"%@",model.operation_count] forState:UIControlStateNormal];
    
    [self.flow setTitle:[NSString stringWithFormat:@"%@",model.flower] forState:UIControlStateNormal];
    
    [self.banner setTitle:[NSString stringWithFormat:@"%@",model.banner] forState:UIControlStateNormal];
}


@end
